1. Field of the Invention
The present invention relates generally to the field of computer graphics, and more specifically to providing a system and method for executing platform-efficient graphics application programs including platform-independent shading language instructions.
2. Related Art
Graphics applications which demand high-quality (photo realistic) shaded rendering (e.g., entertainment industry applications) are typically written using a shading language. Shaded rendering refers to the process of generating a synthetic graphical image of a scene from a mathematical (i.e., geometric and other characteristics) model of the scene, whereas shading refers to the process of computing the light that leaves a point either by self-emission or propagation.
Shading models are mathematical functions that characterize the light leaving a particular point on a surface or in a space. In early development, one was required to select a particular model, characterized by its set of mathematical equations, and select parameters to accomplish rendering. A user was required to intimately know the model and fine tune the parameters to be successful. These models were thus labeled parametric shading models (of which expressions were labeled parametric shading expressions).
Shading languages developed from the need to utilize custom shading models (i.e., a xe2x80x9cshaderxe2x80x9d). A high-level shade tree architecture for building customized shaders was first described in Cook, Shade Trees, Computer Graphics (SIGGRAPH ""84 Proceedings), H. Christiansen, (Ed.), Vol. 18, No. 3, pp. 223-231 (July 1984), which is incorporated herein by reference in its entirety. Cook described an architecture where the shading process was broken down into a number of basic operations which could be organized in a tree-like structurexe2x80x94generally a directed acyclic graph (DAG). Each tree node is basically a function call and a shade tree language program would pass a standard list of parameters to the shade tree, traverse it in post-order, and expect a final color and opacity value to be returned from the root of the tree.
In Perlin, An Image Synthesizer, Computer Graphics (SIGGRAPH ""85 Proceedings), Vol. 19, No. 3, pp. 287-296 (July 1985), which is incorporated herein by reference in its entirety, a similar language-based approach to shading was presented where arbitrary expressions generated pictures from pre-computed visibility information. The ideas of Cook and Perlin were combined in Hanrahan et al., A Language for Shading and Lighting Calculations, Computer Graphics (SIGGRAPH ""90 Proceedings), F. Baskett, (Ed.), Vol. 24, No. 4, pp. 289-298 (Aug.1990), which is incorporated herein by reference in its entirety. The result of that work was the RenderMan(trademark) Shading Language which is well-known in the relevant art. RenderMan(trademark) is described in detail in Upstill, The Render Man(trademark) Companion, Addison-Wesley Publishing Co. (USA 1990), which is incorporated herein by reference in its entirety.
It has always been deemed desirable for shading languages to be platform independent. In other words, their designs have aimed to make it more or less possible to port shaded rendering applications among different hardware platforms, without substantially rewriting the source code version of the shading language instructions. To achieve platform independence, shading language instructions are typically handled by compiling and linking the application to software libraries written in a high-level, platform-independent programming language (e.g., the xe2x80x9cCxe2x80x9d or xe2x80x9cC++xe2x80x9d programming languages), or by using run-time software interpreters similarly written in a high-level language.
Shading languages, via their abstract high-level procedural shading expressions, typically allow programmers to control the display color and opacity of points within a given surface in a flexible and powerful way. For example, a typical set of RenderMan(trademark) Shading Language instructions for a surface that is to be rendered with constant opacity and color is shown in Table 1.
In this simple illustration of a surface shader, the variable Oi represents the surface opacity, and is set to a constant valuexe2x80x94Os. Ci represents the output color, and is set to the product of the constants Cs (surface reflectance) and Os.
In another example, shown in Table 2, a xe2x80x9cplasticxe2x80x9d surface is specified through a more complex series of RenderMan(trademark) shading instructions, which requires taking various lighting-based computations (e.g., diffusion, specular, ambient, etc.) and combining them mathematically.
Together, these instructions model a plastic surface as a solid medium with microscopic colored particles suspended within it. The specular highlight is assumed to be reflected directly off the surface, and the surface color is assumed to be due to the light entering the medium, reflecting off the suspended particles, and re-emerging.
In any event, the examples contained in Table 1 and Table 2 are standard shaders in the RenderMan(trademark) Shading Language which are easily understood by persons skilled in the relevant art.
A current limitation of executing applications with shaded rendering is that they are painfully slow. Conventional graphics hardware systems can easily take several hours or more to render a single, fully-shaded image frame, for a three-dimensional scene of average complexity. This is currently true even for high-end computer graphics systems containing special purpose 3D graphics hardware such as a state-of-the art Silicon Graphics, Inc.""s Onyx2(trademark) workstations equipped with InfiniteReality graphics. Because shading language instructions are typically compiled and linked using a high-level, platform-independent programming language, the net effect is that the operations required by each shading routine are ultimately handled by the general-purpose microprocessor(s) in the user""s computer system. The special-purpose graphics hardware resources in Onyx2(trademark) systems or the like, are simply not tapped.
Furthermore, shading languages, and. graphics application program interfaces (APIs) in general, provide abroad set of primitive commands to specify graphics computations in an ostensibly device-independent manner. However, a limitation of such APIs is that they often allow many distinct, but functionally equivalent, sequences of primitive commands to perform a given computation. The optimal choice, in terms of overall execution time and system resource utilization, among a set of functionally equivalent sequences depends strongly on the underlying hardware or software implementation of the API. This fact undermines the utility of the API as a device abstraction since the programmer must construct distinct sequences for each distinct graphics device in order to achieve optimal performance.
Given the above-described limitations, what is needed is a way of utilizing special purpose graphics hardware resources in order to efficiently execute shaded rendering applications, while preserving the relative platform-independence of such applications. Further, what is needed is a cost-based, run-time compilation system for generating efficient sequences of graphics device commands from an abstract, device-independent computational expression.
The present invention is a system and method for high-speed execution of graphics application programs, including shading language instructions. The method involves the steps of expressing a graphics computation in a platform-independent procedural shading expression, translating it into an intermediate representation such as a tree and then obtaining a sequence of parametric shading expressions that realizes the graphics computation. In a preferred embodiment, the method of the present invention processes the intermediate tree representation of the graphics computation using a cost-based, tree-grammar recognizer such as iburg. This allows the method of the present invention to further obtain a platform-dependent, efficient sequence of primitive commands that realizes the graphics computation.
One advantage of the present invention is that it can be used to translate programs written in one graphics API into programs written in another graphics API. More specifically, the present invention allows platform-independent RenderMan(trademark) Shading Language programs to be translated into platform-specific OpenGL(trademark) or Direct3D(trademark) programs for faster execution.
Another advantage of the present invention is that the method is compiled rather than interpreted. This is different from other language-based graphics environments. Consequently, the present invention allows re-targeting to different hardware/software implementations and re-targeting to different low-level APIs.
Yet another advantage of the present invention is that it differs from conventional ad hoc graph-based optimizations. In a preferred embodiment of the present invention, iburg is used as a cost-based, tree-grammar recognizer. This allows for a systematic search for an efficient (or least-cost) sequence of primitive commands using well-defined cost functions. This also allows a semi-automated port to new platforms (i.e., a self-calibration procedure) and a mechanism to add user-defined optimizations.
Further features and advantages of the invention as well as the structure and operation of various embodiments of the present invention are described in detail below with reference to the accompanying drawings.